home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / machserver / 1.098 / vm / vmTrace.h < prev    next >
C/C++ Source or Header  |  1990-09-12  |  10KB  |  296 lines

  1. /*
  2.  * vmTrace.h --
  3.  *
  4.  *     Virtual memory data structures and procedure headers for tracing.
  5.  *
  6.  * Copyright 1986 Regents of the University of California
  7.  * All rights reserved.
  8.  *
  9.  *
  10.  * $Header: /sprite/src/kernel/vm/RCS/vmTrace.h,v 9.2 90/09/12 13:36:52 shirriff Exp $ SPRITE (Berkeley)
  11.  */
  12.  
  13. #ifndef _VMTRACE
  14. #define _VMTRACE
  15.  
  16. #ifdef KERNEL
  17. #include <vmMachTrace.h>
  18. #include <vmStat.h>
  19. #include <spriteTime.h>
  20. #else
  21. #include <kernel/vmMachTrace.h>
  22. #include <vmStat.h>
  23. #include <spriteTime.h>
  24. #endif
  25.  
  26. /*
  27.  * Definition for the trace buffer.  The trace buffer is a circular buffer.
  28.  * The indices into the buffer are managed as if the buffer was infinite in
  29.  * size.  Thus when one of the indices is used it has to be done as
  30.  * (index & (VM_TRACE_BUFFER_SIZE - 1)).  vmTraceFirstByte contains the
  31.  * index of the first valid byte in the buffer and vmTraceNextByte contains
  32.  * the index of where the next byte is to be put.  In no case can
  33.  * vmTraceNextByte - vmTraceFirstByte exceed VM_TRACE_BUFFER_SIZE.
  34.  */
  35. #define    VM_TRACE_BUFFER_SIZE    (32 * 1024)
  36. #define    VM_TRACE_BUF_MASK    (~(VM_TRACE_BUFFER_SIZE - 1))
  37. extern    char        *vmTraceBuffer;
  38. extern    int        vmTraceFirstByte;
  39. extern    int        vmTraceNextByte;
  40.  
  41. /*
  42.  * Macro to go from an infinite buffer index (i.e. vmTraceNextByte) to
  43.  * an index that fits in the buffer.
  44.  */
  45. #define    VM_GET_BUFFER_INDEX(index) (index & (VM_TRACE_BUFFER_SIZE - 1))
  46.  
  47. /*
  48.  * Macro to get a pointer to the next trace record.
  49.  */
  50. #define    VM_GET_TRACE_BUFFER_PTR(type) \
  51.     (type *)(vmTraceBuffer + VM_GET_BUFFER_INDEX(vmTraceNextByte))
  52.  
  53. /*
  54.  * Trace stats.
  55.  */
  56. typedef struct {
  57.     int            traceDumps;
  58.     int            traceDrops;
  59.     int            numTraces;
  60.     VmMach_TraceStats    machStats;
  61. } Vm_TraceStats;
  62. extern    Vm_TraceStats    vmTraceStats;
  63.  
  64. /*
  65.  * The different record types.  The first short of each record determines its
  66.  * type.  If it is not one of the three types below then it is a page
  67.  * reference, modify record type since these types never have the sign bit set.
  68.  *
  69.  *    VM_TRACE_START_REC    A record of type Vm_TraceStart.
  70.  *    VM_TRACE_END_REC    A record of type Vm_TraceEnd.
  71.  *    VM_TRACE_TIME_REC    A record of type Vm_TraceTimeStamp
  72.  *    VM_TRACE_SEG        A record of type Vm_TraceSeg
  73.  *    VM_TRACE_SKIP_REC    This type means that should skip bytes up
  74.  *                until hit a multiple of VM_TRACE_BUFFER_SIZE.
  75.  *    VM_TRACE_STEAL_PMEG_REC    The following segment record relates to a
  76.  *                stolen PMEG.
  77.  *    VM_TRACE_SEG_CREATE_REC    A record of type Vm_TraceSegCreate.
  78.  *    VM_TRACE_SEG_DESTROY_REC A record of type Vm_TraceSegDestroy.
  79.  *    VM_TRACE_PTE_CHANGE_REC    A record of type Vm_TracePTEChangeRec.
  80.  *    VM_TRACE_CLEAR_COW_REC    A record of type Vm_TraceClearCOW
  81.  *    VM_TRACE_PAGE_FAULT_REC    A record of type Vm_TracePageFault
  82.  *    VM_TRACE_END_INIT_REC    Trace initialization has completed.
  83.  */
  84. #define    VM_TRACE_START_REC        -1
  85. #define    VM_TRACE_END_REC        -2
  86. #define    VM_TRACE_TIME_REC        -3
  87. #define    VM_TRACE_SEG_REC        -4
  88. #define    VM_TRACE_SKIP_REC        -5
  89. #define    VM_TRACE_STEAL_PMEG_REC        -6
  90. #define    VM_TRACE_SEG_CREATE_REC        -7
  91. #define    VM_TRACE_SEG_DESTROY_REC    -8
  92. #define    VM_TRACE_PTE_CHANGE_REC        -9
  93. #define    VM_TRACE_CLEAR_COW_REC        -10
  94. #define    VM_TRACE_PAGE_FAULT_REC        -11
  95. #define    VM_TRACE_END_INIT_REC        -12
  96. #define    VM_TRACE_MIN_REC_TYPE        -12
  97.  
  98. /*
  99.  * Start trace record.
  100.  */
  101. typedef struct {
  102.     short    recType;        /* Always equals VM_TRACE_START_REC. */
  103.     int        hostID;            /* Sprite host number. */
  104.     int        pageSize;        /* The page size. */
  105.     int        numPages;        /* The number of physical pages. */
  106.     Address    codeStartAddr;        /* The starting address of the kernel's
  107.                      * code (runs up to dataStartAddr). */
  108.     Address    dataStartAddr;        /* The starting address of the kernel's
  109.                      * data (runs up to stackStartAddr). */
  110.     Address    stackStartAddr;        /* The start of the range of virtual
  111.                      * addresses that are used for kernel
  112.                      * stacks (runs up to mapStartAddr). */
  113.     Address    mapStartAddr;        /* The start of kernel virtual
  114.                      * addresses used for mapping stuff
  115.                      * (runs up to cacheStartAddr). */
  116.     Address    cacheStartAddr;        /* The start of the FS cache. */
  117.     Address    cacheEndAddr;        /* The end of the FS cache. */
  118.     Vm_Stat    startStats;        /* Stats at the start of the trace. */
  119.     int        tracesPerSecond;    /* The number of traces per second. */
  120. } Vm_TraceStart;
  121.  
  122. /*
  123.  * End trace record.
  124.  */
  125. typedef struct {
  126.     short        recType;    /* Always equals VM_TRACE_END_REC. */
  127.     Vm_Stat        endStats;    /* Stats at the end of the trace. */
  128.     Vm_TraceStats    traceStats;    /* Trace stats. */
  129. } Vm_TraceEnd;
  130.  
  131. /*
  132.  * Trace time stamp record.
  133.  */
  134. typedef struct {
  135.     short        recType;    /* Always equals VM_TRACE_TIME_REC. */
  136.     Time        time;
  137. } Vm_TraceTimeStamp;
  138.  
  139. /*
  140.  * Segment trace begin record.
  141.  */
  142. typedef struct {
  143.     short        recType;    /* Always equals VM_TRACE_SEG_REC. */
  144.     unsigned    short    hardSegNum;    /* Which hardware segment.  Hardware
  145.                      * segments are a multiple of 32K on
  146.                      * Sun-2s and 128K on Sun3's. */
  147.     unsigned    short    softSegNum;    /* Which of the 256 software segments.*/
  148.     unsigned    char    segType;    /* One of VM_SYSTEM, VM_CODE, VM_HEAP,
  149.                      * VM_STACK. */
  150.     unsigned    char    refCount;    /* Number of processes that are using
  151.                      * the segment. */
  152. } Vm_TraceSeg;
  153.  
  154. /*
  155.  * Page reference, modified trace record.  The lower 4 bits contain which
  156.  * page within the hardware segment that this page is and the high order byte
  157.  * contains info as to whether the page was referenced or modified.
  158.  */
  159. #define    VM_TRACE_REFERENCED    0x100
  160. #define    VM_TRACE_MODIFIED    0x200
  161.  
  162. typedef unsigned short    Vm_TracePage;
  163.  
  164. /*
  165.  * Segment creation record.
  166.  */
  167. typedef struct {
  168.     short    recType;    /* Always VM_TRACE_SEG_CREATE_REC. */
  169.     short    segNum;        /* The segment being created. */
  170.     short    parSegNum;    /* The parent segment. */
  171.     char    segType;    /* The type of segment. */
  172.     char    cor;        /* TRUE if the segment was created
  173.                  * copy-on-reference. */
  174. } Vm_TraceSegCreate;
  175.  
  176. /*
  177.  * Segment destruction record.
  178.  */
  179. typedef struct {
  180.     short    recType;    /* Always VM_TRACE_SEG_DESTROY_REC. */
  181.     short    segNum;        /* The segment being destroyed. */
  182. } Vm_TraceSegDestroy;
  183.  
  184. /*
  185.  * PTE Change record.
  186.  */
  187. typedef struct {
  188.     short        recType;    /* Always VM_TRACE_PTE_CHANGE_REC. */
  189.     char        softPTE;    /* TRUE if is the software page table
  190.                      * entry and FALSE if is the hardware
  191.                      * one. */
  192.     char        changeType;    /* Type    of pte change (defined below)*/
  193.     short        segNum;        /* The segment that the page is in. */
  194.     unsigned short    pageNum;    /* The virtual page number. */
  195.     unsigned int    beforePTE;    /* The PTE before the change. */
  196.     unsigned int    afterPTE;    /* The PTE after the change. */
  197. } Vm_TracePTEChange;
  198.  
  199. /*
  200.  * Types of PTE changes.
  201.  *
  202.  *    VM_TRACE_CLEAR_REF_BIT        The reference bit was cleared.
  203.  *    VM_TRACE_CLEAR_MOD_BIT        The modified bit was cleared.
  204.  *    VM_TRACE_SET_PAGE_PROT        The page protection was set.
  205.  *    VM_TRACE_SET_SEG_PROT        The protection of the entire segment
  206.  *                    was set.
  207.  *    VM_TRACE_VALIDATE_PAGE        A page was validated.
  208.  *    VM_TRACE_INVALIDATE_PAGE    A page was invalidated.
  209.  *    VM_TRACE_LAST_COR        The last copy-on-reference slave
  210.  *                    was removed.
  211.  *    VM_TRACE_COW_TO_NORMAL        A page is being changed from COW to
  212.  *                    normal protection because of a
  213.  *                    copy-on-write fault.
  214.  *    VM_TRACE_GIVEN_FROM_MASTER    The master segment is invalidating
  215.  *                    its copy of the page so that it can
  216.  *                    give it to a slave.
  217.  *    VM_TRACE_TAKEN_BY_SLAVE        The slave segment took the page from
  218.  *                    the master when the master gave it
  219.  *                    away with VM_TRACE_GIVEN_FROM_MASTER.
  220.  *    VM_TRACE_COW_COR_CHANGE        A generic copy-on-write change.
  221.  */
  222. #define    VM_TRACE_CLEAR_REF_BIT        1
  223. #define    VM_TRACE_CLEAR_MOD_BIT        2
  224. #define    VM_TRACE_SET_PAGE_PROT        3
  225. #define    VM_TRACE_SET_SEG_PROT        4
  226. #define    VM_TRACE_VALIDATE_PAGE        5
  227. #define    VM_TRACE_INVALIDATE_PAGE    6
  228. #define    VM_TRACE_LAST_COR        7
  229. #define    VM_TRACE_COW_TO_NORMAL        8
  230. #define    VM_TRACE_GIVEN_FROM_MASTER    9
  231. #define    VM_TRACE_TAKEN_BY_SLAVE        10
  232. #define    VM_TRACE_COW_COR_CHANGE        11
  233. #define    VM_TRACE_MAX_PTE_CHANGE_TYPE    11
  234.  
  235. /*
  236.  * Page fault type record.
  237.  */
  238. typedef struct {
  239.     short        recType;    /* Always VM_TRACE_PAGE_FAULT_REC. */
  240.     short        segNum;        /* The segment that the page is in. */
  241.     unsigned short    pageNum;    /* The virtual page number. */
  242.     short        faultType;    /* One of VM_TRACE_ZERO_FILL,
  243.                      * VM_TRACE_OBJ_FILE,
  244.                      * VM_TRACE_SWAP_FILE. */
  245. } Vm_TracePageFault;
  246.  
  247. /*
  248.  * Different types of page faults:
  249.  *
  250.  *    VM_TRACE_ZERO_FILL    Page was zero filled.
  251.  *    VM_TRACE_OBJ_FILE    Page was demand loaded from the object file.
  252.  *    VM_TRACE_SWAP_FILE    Page was loaded in from the swap file.
  253.  */
  254. #define    VM_TRACE_ZERO_FILL    1
  255. #define    VM_TRACE_OBJ_FILE    2
  256. #define    VM_TRACE_SWAP_FILE    3
  257.  
  258. /*
  259.  * Clear copy-on-write record.
  260.  */
  261. typedef struct {
  262.     short        recType;    /* Always VM_TRACE_CLEAR_COW_REC. */
  263.     short        segNum;        /* The segment that is being made to
  264.                      * be no longer copy-on-write. */
  265. } Vm_TraceClearCOW;
  266.  
  267. /*
  268.  * Variable to indicate which trace iteration that this is.  Is incremented
  269.  * every time a trace is taken.
  270.  */
  271. extern    int        vmTraceTime;
  272. extern    Boolean        vmTraceNeedsInit;
  273. extern    int        vmTracesPerClock;
  274. extern    int        vmTracesToGo;
  275. extern    Fs_Stream    *vmTraceFilePtr;
  276. extern    char        *vmTraceFileName;
  277. extern    Boolean        vmTraceDumpStarted;
  278.  
  279. /*
  280.  * The name of the trace file is the following followed by the host on
  281.  * which the trace is occuring.
  282.  */
  283. #define    VM_TRACE_FILE_NAME    "/sprite/vmtrace/tfile."
  284.  
  285. /*
  286.  * Trace dump file and function to do the tracing.
  287.  */
  288. extern    Fs_Stream    *vmTraceFilePtr;
  289. extern    char        *vmTraceFileName;
  290. extern    Boolean        vmTraceDumpStarted;
  291. extern void VmTraceDump _ARGS_((ClientData data, Proc_CallInfo *callInfoPtr));
  292. extern void VmStoreTraceRec _ARGS_((int recType, int size, Address traceRecAddr, Boolean checkOverflow));
  293. extern void VmCheckTraceOverflow _ARGS_((void));
  294.  
  295. #endif /* _VMTRACE */
  296.